var o = {};

var test = new Function();
test.prototype = o;

o.add = function() {
	$.ligerDialog.prompt('新增', function(yes, value) {
		if (yes) {
			$.ajax( {
				type : "POST",
				url : "test-add.action",
				data : "test.name=" + value,
				success : function(msg) {
					alert(msg.jsonResult);
					window.location.reload(false);
				},
				error : function(XMLHttpRequest, textStatus, errorThrown) {
					alert("出错了：" + errorThrown);
				}
			});
		}
	});
}

o.edit = function(id, name) {
	$.ligerDialog.prompt('编辑', name, function(yes, value) {
		if (yes) {
			$.ajax( {
				type : "POST",
				url : "test-edit.action",
				data : "test.name=" + value + "&test.id=" + id,
				success : function(msg) {
					alert(msg.jsonResult);
					window.location.reload(false);
				},
				error : function(XMLHttpRequest, textStatus, errorThrown) {
					alert("出错了：" + errorThrown);
				}
			});
		}
	});
}

/**
 * 选择
 */
o.checkInAll = function(obj) {
	if (obj.attr('checked') == true) {
		$('.sList .selectItem').attr('checked', 'checked');
	} else {
		$('.sList .selectItem').attr('checked', '');
	}
}
/**
 * 删除
 */
o.delBatch = function() {
	var ids = "";
	$('.sList .selectItem').each( function() {
		if ($(this).attr("checked")) {
			if (ids == "")
				ids = $(this).val();
			else
				ids = ids + "," + $(this).val();
		}
	});
	if (ids == "") {
		alert("请选择要删除的记录!");
		return;
	}
	$.ajax( {
		type : "POST",
		url : "test-delete.action",
		data : "ids=" + ids,
		success : function(msg) {
			window.location.reload(false);
		},
		error : function(XMLHttpRequest, textStatus, errorThrown) {
			alert("出错了：" + errorThrown);
		}
	});
}

$( function() {
	// all select
	$('.sList .allSelect').click( function() {
		test.checkInAll($(this));
	});
	// delete
	$('#delBatch').click( function() {
		test.delBatch();
	});
});

var test=new test();